package cn.edu.swufe.stu2025.rateexample;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class RateCalculatorActivity extends AppCompatActivity {
    private double exchangeRate;
    private  String initText;
    String TAG="RateCalculatorActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate_calculator);

        // 获取传递的汇率
        Intent intent = getIntent();
        exchangeRate = intent.getDoubleExtra("exchangeRate", 0.0);
        initText = intent.getStringExtra("initText");
        EditText amountInput = findViewById(R.id.amountInput);
        Button calculateButton = findViewById(R.id.calculateButton);
        TextView resultView = findViewById(R.id.resultView);
        TextView initView = findViewById(R.id.initText);

        calculateButton.setOnLongClickListener(v->{
            Log.i(TAG, "setOnLongClickListener: ");
            return true;
        });
        // 设置按钮点击事件
        calculateButton.setOnClickListener(v -> {
            initView.setText(initText);
            String amountStr = amountInput.getText().toString();
            if (!amountStr.isEmpty()) {
                double amount = Double.parseDouble(amountStr);
                double result = amount * exchangeRate;
                resultView.setText("结果: " + result);
            } else {
                resultView.setText("请输入金额");
            }
        });


    }
}